package com.example.customView;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

/**
 * Created by morton on 2015/7/26.
 */
public class CustomClickView1 extends TextView implements View.OnClickListener {

    private Paint mPaint = null;
    private int mCount = 100;
    private Rect mBound = null;

    public CustomClickView1(Context context, AttributeSet attrs) {
        super(context, attrs);
        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mBound = new Rect();

        setOnClickListener(this);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        mPaint.setColor(Color.RED);
        canvas.drawRect(0, 0, getWidth(), getHeight(), mPaint);

        mPaint.setColor(Color.BLUE);
        mPaint.setTextSize(80);
        String text = String.valueOf(mCount);
        mPaint.getTextBounds(text, 0, text.length(), mBound);
        float textWidth = mBound.width();
        float textHeight = mBound.height();
        canvas.drawText(text, getWidth() / 2 - textWidth / 2, getHeight() / 2 + textHeight / 3, mPaint);
    }

    @Override
    public void onClick(View v) {
        Log.i("args","width"+String.valueOf(getWidth()));
        Log.i("args","measure_width"+String.valueOf(getMeasuredWidth()));

        Log.i("args","height"+getHeight());
        Log.i("args","measure_heigth"+getMeasuredHeight());
        mCount++;
        invalidate();
    }
}
